home *** CD-ROM | disk | FTP | other *** search
- package symjava.sql;
-
- import java.util.Date;
-
- public class Time extends Date {
- public Time(int hour, int minute, int second) {
- super(70, 0, 1, hour, minute, second);
- }
-
- public Time(long time) {
- super(time);
- }
-
- public static Time valueOf(String s) {
- if (s == null) {
- throw new IllegalArgumentException();
- } else {
- int firstColon = s.indexOf(58);
- int secondColon = s.indexOf(58, firstColon + 1);
- if (firstColon > 0 & secondColon > 0 & secondColon < s.length() - 1) {
- int hour = Integer.parseInt(s.substring(0, firstColon));
- int minute = Integer.parseInt(s.substring(firstColon + 1, secondColon));
- int second = Integer.parseInt(s.substring(secondColon + 1));
- return new Time(hour, minute, second);
- } else {
- throw new IllegalArgumentException();
- }
- }
- }
-
- public String toString() {
- int hour = super.getHours();
- int minute = super.getMinutes();
- int second = super.getSeconds();
- String hourString;
- if (hour < 10) {
- hourString = "0" + hour;
- } else {
- hourString = Integer.toString(hour);
- }
-
- String minuteString;
- if (minute < 10) {
- minuteString = "0" + minute;
- } else {
- minuteString = Integer.toString(minute);
- }
-
- String secondString;
- if (second < 10) {
- secondString = "0" + second;
- } else {
- secondString = Integer.toString(second);
- }
-
- return hourString + ":" + minuteString + ":" + secondString;
- }
- }
-